package com.woniu.shop.controller;

import com.woniu.Result;
import com.woniu.shop.pojo.Application;
import com.woniu.shop.pojo.vo.AcceptApplicationVo;
import com.woniu.shop.pojo.vo.AllApplicationVo;
import com.woniu.shop.pojo.vo.ApplicationAcceptDto;
import com.woniu.shop.pojo.vo.ApplicationVo;
import com.woniu.shop.rabibit.ConfirmProducer;
import com.woniu.shop.service.IApplicationService;
import com.woniu.shop.utils.IdCardOCRVerification;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaohuang
 * @since 2022-11-16
 */
@RestController
@RequestMapping("/application")
@Api(tags = "加盟申请管理")
public class ApplicationController {
    @Autowired
    private IApplicationService applicationService;

    @Autowired
    private ConfirmProducer confirmProducer;

    @ApiOperation("添加申请")
    @PostMapping
    public Result<String> saveApplication(@RequestBody ApplicationVo applicationVo){
        Result<String> result = applicationService.saveApplication(applicationVo);
        return result;

    }

    @ApiOperation("通过申请id查看信息")
    @GetMapping("/{id}")
    private Result<ApplicationVo> getById(@PathVariable Integer id){
        ApplicationVo applicationVo = applicationService.findById(id);
        return Result.ok(applicationVo);
    }

    @ApiOperation("查询所有")
    @GetMapping("/all/{userId}")
    public Result<List<AllApplicationVo>> findAll(@PathVariable Integer userId){
        List<AllApplicationVo> list = applicationService.findAll(userId);
        return Result.ok(list);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result<String> modify(@RequestBody ApplicationVo applicationVo){
        Result<String> result = applicationService.modify(applicationVo);
        return result;
    }

    @ApiOperation("mq测试")
    @GetMapping("/test/{id}")
    public Result<String> test01(@PathVariable Integer id){
        confirmProducer.producerConfirm(id);
        return Result.ok();
    }

    @PostMapping("/oneAudit")
    @ApiOperation("一审")
    public Result<String> oneAudit(@RequestBody Application application){
        Result<String> result = applicationService.oneAudit(application);
        return result;
    }

    @PostMapping("/twoAudit")
    @ApiOperation("二审")
    public Result<String> twoAudit(@RequestBody Application application){
        Result<String> result = applicationService.twoAudit(application);
        return result;
    }

    @PutMapping("/accept")
    @ApiOperation("审核通过")
    public Result<AcceptApplicationVo> accept(@RequestBody ApplicationAcceptDto dto){
        Result<AcceptApplicationVo> vo = applicationService.accept(dto);
        return vo;
    }

}
